/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package SubsistemaPaciente.programaMedico;


import clienteSandraParada.Login;
import java.awt.Color;
import java.io.FileNotFoundException;
import java.io.IOException;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author Mario
 */
public class ProgramaMedicoFonasa extends javax.swing.JPanel {
        
    DialogoInfoProgramaMedicoFonasa dialogo;
            
    public ProgramaMedicoFonasa() throws FileNotFoundException, IOException {
        initComponents();
        this.actualizarTabla();
        dialogo = new DialogoInfoProgramaMedicoFonasa(null, true, this);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        dialogoEliminarPrograma = new javax.swing.JDialog();
        jPanel8 = new javax.swing.JPanel();
        etiquetaEliminar = new javax.swing.JLabel();
        jLabel18 = new javax.swing.JLabel();
        botonSiEliminar = new javax.swing.JButton();
        botonNoEliminar = new javax.swing.JButton();
        jPanel5 = new javax.swing.JPanel();
        jLabel4 = new javax.swing.JLabel();
        jScrollPane4 = new javax.swing.JScrollPane();
        contenedorProgramas = new javax.swing.JTable();
        datosABuscar = new javax.swing.JTextField();
        jPanel7 = new javax.swing.JPanel();
        botonAgregarPrograma = new javax.swing.JButton();
        botonModificarPrograma = new javax.swing.JButton();
        botonVerPrograma = new javax.swing.JButton();
        jPanel6 = new javax.swing.JPanel();
        etiquetaMensajeria = new javax.swing.JLabel();

        dialogoEliminarPrograma.setTitle("Eliminar paciente");
        dialogoEliminarPrograma.setMinimumSize(new java.awt.Dimension(550, 190));
        dialogoEliminarPrograma.setModal(true);
        dialogoEliminarPrograma.setResizable(false);

        etiquetaEliminar.setText("¿Confirma que desea enviar a la papelera los programas médicos seleccionados?");

        jLabel18.setIcon(new javax.swing.ImageIcon(getClass().getResource("/GUI/Img/Iconos35X35/Papelera.png"))); // NOI18N

        javax.swing.GroupLayout jPanel8Layout = new javax.swing.GroupLayout(jPanel8);
        jPanel8.setLayout(jPanel8Layout);
        jPanel8Layout.setHorizontalGroup(
            jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel8Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel18)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(etiquetaEliminar)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel8Layout.setVerticalGroup(
            jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel8Layout.createSequentialGroup()
                .addGap(40, 40, 40)
                .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel18)
                    .addGroup(jPanel8Layout.createSequentialGroup()
                        .addGap(9, 9, 9)
                        .addComponent(etiquetaEliminar)))
                .addContainerGap(24, Short.MAX_VALUE))
        );

        botonSiEliminar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/GUI/Img/Iconos16X16/Aceptar.png"))); // NOI18N
        botonSiEliminar.setText("Si");
        botonSiEliminar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonSiEliminarActionPerformed(evt);
            }
        });

        botonNoEliminar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/GUI/Img/Iconos16X16/Cancelar.png"))); // NOI18N
        botonNoEliminar.setText("No");
        botonNoEliminar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonNoEliminarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout dialogoEliminarProgramaLayout = new javax.swing.GroupLayout(dialogoEliminarPrograma.getContentPane());
        dialogoEliminarPrograma.getContentPane().setLayout(dialogoEliminarProgramaLayout);
        dialogoEliminarProgramaLayout.setHorizontalGroup(
            dialogoEliminarProgramaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel8, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, dialogoEliminarProgramaLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(botonSiEliminar, javax.swing.GroupLayout.PREFERRED_SIZE, 78, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(botonNoEliminar, javax.swing.GroupLayout.PREFERRED_SIZE, 78, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        dialogoEliminarProgramaLayout.setVerticalGroup(
            dialogoEliminarProgramaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(dialogoEliminarProgramaLayout.createSequentialGroup()
                .addComponent(jPanel8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(dialogoEliminarProgramaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(botonSiEliminar)
                    .addComponent(botonNoEliminar))
                .addGap(0, 15, Short.MAX_VALUE))
        );

        setPreferredSize(new java.awt.Dimension(953, 603));

        jPanel5.setBackground(new java.awt.Color(255, 255, 255));
        jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1), "Programa Médico FONASA", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.TOP, new java.awt.Font("Tahoma", 0, 36))); // NOI18N

        jLabel4.setText("Buscar ");

        contenedorProgramas.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Número Programa", "Rut afiliado", "Nombre afiliado", "Rut paciente", "Nombre paciente", "Rut establecimiento", "Nombre establecimiento", "Rut profesional", "Nombre profesional", "Diagnostico"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.Object.class, java.lang.Object.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.Object.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false, false, false, false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        contenedorProgramas.getTableHeader().setReorderingAllowed(false);
        contenedorProgramas.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                contenedorProgramasMouseClicked(evt);
            }
        });
        jScrollPane4.setViewportView(contenedorProgramas);

        datosABuscar.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                datosABuscarKeyReleased(evt);
            }
        });

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap(764, Short.MAX_VALUE)
                .addComponent(jLabel4)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(datosABuscar, javax.swing.GroupLayout.PREFERRED_SIZE, 176, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addComponent(jScrollPane4, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 943, Short.MAX_VALUE)
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(datosABuscar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane4, javax.swing.GroupLayout.DEFAULT_SIZE, 409, Short.MAX_VALUE)
                .addContainerGap())
        );

        jPanel7.setBackground(new java.awt.Color(255, 255, 255));

        botonAgregarPrograma.setIcon(new javax.swing.ImageIcon(getClass().getResource("/GUI/Img/Iconos35X35/Agregar.png"))); // NOI18N
        botonAgregarPrograma.setText("Agregar");
        botonAgregarPrograma.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        botonAgregarPrograma.setMargin(new java.awt.Insets(2, 4, 2, 6));
        botonAgregarPrograma.setMaximumSize(new java.awt.Dimension(97, 43));
        botonAgregarPrograma.setMinimumSize(new java.awt.Dimension(97, 43));
        botonAgregarPrograma.setPreferredSize(new java.awt.Dimension(97, 43));
        botonAgregarPrograma.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonAgregarProgramaMedico(evt);
            }
        });

        botonModificarPrograma.setIcon(new javax.swing.ImageIcon(getClass().getResource("/GUI/Img/Iconos35X35/Edit.png"))); // NOI18N
        botonModificarPrograma.setText("Modificar");
        botonModificarPrograma.setMargin(new java.awt.Insets(2, 4, 2, 6));
        botonModificarPrograma.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonModificarProgramaActionPerformed(evt);
            }
        });

        botonVerPrograma.setIcon(new javax.swing.ImageIcon(getClass().getResource("/GUI/Img/Iconos35X35/Previsualizar.png"))); // NOI18N
        botonVerPrograma.setText("Ver");
        botonVerPrograma.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        botonVerPrograma.setMargin(new java.awt.Insets(2, 4, 2, 6));
        botonVerPrograma.setMaximumSize(new java.awt.Dimension(97, 43));
        botonVerPrograma.setMinimumSize(new java.awt.Dimension(97, 43));
        botonVerPrograma.setPreferredSize(new java.awt.Dimension(97, 43));
        botonVerPrograma.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonVerProgramaActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel7Layout = new javax.swing.GroupLayout(jPanel7);
        jPanel7.setLayout(jPanel7Layout);
        jPanel7Layout.setHorizontalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel7Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(botonAgregarPrograma, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(botonModificarPrograma, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(botonVerPrograma, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        jPanel7Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {botonAgregarPrograma, botonModificarPrograma, botonVerPrograma});

        jPanel7Layout.setVerticalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addGap(13, 13, 13)
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(botonModificarPrograma)
                    .addComponent(botonVerPrograma, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(botonAgregarPrograma, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        jPanel7Layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {botonAgregarPrograma, botonModificarPrograma, botonVerPrograma});

        jPanel6.setBackground(new java.awt.Color(255, 255, 255));

        etiquetaMensajeria.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        etiquetaMensajeria.setText("Área Mensajería");

        javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
        jPanel6.setLayout(jPanel6Layout);
        jPanel6Layout.setHorizontalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(etiquetaMensajeria, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        jPanel6Layout.setVerticalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(etiquetaMensajeria, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 27, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jPanel7, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jPanel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void botonModificarProgramaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonModificarProgramaActionPerformed
        service.Privilegios pri = (service.Privilegios) cargarPrivilegios(Login.getUser().getRut());
        if(pri.isModificarProgramaMedicoFonasa()){
            this.normalizarEtiquetaMensajeria();            
            if(contenedorProgramas.getSelectedRow() == -1){
                this.cambiarEtiquetaMensajeria("Debe seleccionar un programa médico para ser modificado", Color.red);
            }
            else{
                dialogo.normalizarMensajeria();
                dialogo.setLocationRelativeTo(null);
                dialogo.setTitle("Modificar Programa Médico");
                dialogo.limpiarCampos();
                dialogo.getBotonAceptar().setText("Guardar");            
                dialogo.getBotonAceptar().setIcon(new javax.swing.ImageIcon(getClass().getResource("/GUI/Img/Iconos16X16/Aceptar.png")));
                dialogo.getBotonCancelar().setText("Cancelar");
                service.ProgramaMedicoFonasa p = (service.ProgramaMedicoFonasa)cargarProgramaFonasaPorNumero((String)(contenedorProgramas.getValueAt(contenedorProgramas.getSelectedRow(),0)));
                dialogo.llenarCampos(p);
                dialogo.sp = p;                
                dialogo.inhabilitarCampos();
                dialogo.habilitarCampos();                          
                dialogo.rutFocusLost();
                dialogo.setVisible(true);
            }
        }
        else
            JOptionPane.showMessageDialog(this,"No tiene permisos para esta acción, \n contacte al administrador para más información");
    }//GEN-LAST:event_botonModificarProgramaActionPerformed
        
    private void botonVerProgramaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonVerProgramaActionPerformed
        service.Privilegios pri = (service.Privilegios) cargarPrivilegios(Login.getUser().getRut());
        if(pri.isVerProgramaMedicoFonasa()){            
            if(contenedorProgramas.getSelectedRow() == -1){
                this.cambiarEtiquetaMensajeria("Debe seleccionar un programa para verlo", Color.red);
            }
            else{
                this.normalizarEtiquetaMensajeria();
                dialogo.setLocationRelativeTo(null);
                dialogo.setTitle("Ver Programa médico");
                dialogo.getBotonAceptar().setText("Imprimir");
                dialogo.getBotonAceptar().setIcon(new javax.swing.ImageIcon(getClass().getResource("/GUI/Img/Iconos16X16/Imprimir.png")));
                dialogo.getBotonCancelar().setText("Cerrar");
                service.ProgramaMedicoFonasa p = (service.ProgramaMedicoFonasa)cargarProgramaFonasaPorNumero((String)contenedorProgramas.getValueAt(contenedorProgramas.getSelectedRow(),0));
                dialogo.llenarCampos(p);
                
                dialogo.inhabilitarCampos();
                dialogo.setVisible(true);
                 
            }          
        }
        else
            JOptionPane.showMessageDialog(this,"No tiene permisos para esta acción, \n contacte al administrador para más información");
    }//GEN-LAST:event_botonVerProgramaActionPerformed

    private void botonAgregarProgramaMedico(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonAgregarProgramaMedico
        service.Privilegios p = (service.Privilegios) cargarPrivilegios(Login.getUser().getRut());
        if(p.isAgregarProgramaMedicoFonasa()){
            this.normalizarEtiquetaMensajeria();
            dialogo = new DialogoInfoProgramaMedicoFonasa(null, true, this);
            dialogo.normalizarMensajeria();
            dialogo.setLocationRelativeTo(null);
            dialogo.limpiarCampos();
            dialogo.setTitle("Agregar Programa médico");
            dialogo.getBotonAceptar().setText("Agregar");
            dialogo.getBotonAceptar().setIcon(new javax.swing.ImageIcon(getClass().getResource("/GUI/Img/Iconos16X16/Agregar.png")));
            dialogo.getBotonCancelar().setText("Cancelar");
            dialogo.inhabilitarCampos();
            dialogo.habilitarCampos();
            dialogo.setVisible(true);
        }
        else
            JOptionPane.showMessageDialog(this,"No tiene permisos para esta acción, \n contacte al administrador para más información");
    }//GEN-LAST:event_botonAgregarProgramaMedico

    private void botonSiEliminarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonSiEliminarActionPerformed
       
    }//GEN-LAST:event_botonSiEliminarActionPerformed

    private void botonNoEliminarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonNoEliminarActionPerformed
        dialogoEliminarPrograma.dispose();
    }//GEN-LAST:event_botonNoEliminarActionPerformed

    private void datosABuscarKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_datosABuscarKeyReleased
        service.Privilegios p = (service.Privilegios) cargarPrivilegios(Login.getUser().getRut());
        if (p.isBuscarProgramaMedicoFonasa()) {
            if (!datosABuscar.getText().equals("")) {
                limpiarTabla();
                java.util.List<service.ProgramaMedicoFonasa> lista = filtrarProgramaFonasa(datosABuscar.getText());
                filtrarTabla(lista);
            } else {
                limpiarTabla();
                actualizarTabla();
            }
        }
    }//GEN-LAST:event_datosABuscarKeyReleased

    private void contenedorProgramasMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_contenedorProgramasMouseClicked
        int fila = contenedorProgramas.rowAtPoint(evt.getPoint());
        if ((fila > -1) && evt.getClickCount() == 2) {
            botonVerProgramaActionPerformed(null);
        }
    }//GEN-LAST:event_contenedorProgramasMouseClicked
    public void filtrarTabla(java.util.List<service.ProgramaMedicoFonasa> programas) {
        this.limpiarTabla();
        int i = 0;
        for (service.ProgramaMedicoFonasa p : programas) {
            if (p.isVisible()) {
                this.agregarFila();
                service.Paciente afiliado = (service.Paciente) cargarPaciente(p.getRutAfiliado());
                service.Paciente paciente = (service.Paciente) cargarPaciente(p.getRutPaciente());
                service.Establecimiento est= (service.Establecimiento) cargarEstablecimiento(p.getRutEstablecimiento());
                service.Usuario prof = (service.Usuario) cargarUsuario(p.getRutProfesional());
                contenedorProgramas.setValueAt(p.getNumeroPrograma(), i, 0);
                contenedorProgramas.setValueAt(p.getRutAfiliado(), i, 1);
                contenedorProgramas.setValueAt(afiliado.getNombres()+" "+afiliado.getApellidoPaterno()+" "+afiliado.getApellidoMaterno(), i, 2);
                contenedorProgramas.setValueAt(p.getRutPaciente(), i, 3);
                contenedorProgramas.setValueAt(paciente.getNombres()+" "+paciente.getApellidoPaterno()+" "+paciente.getApellidoMaterno(), i, 4);
                contenedorProgramas.setValueAt(p.getRutEstablecimiento(), i, 5);
                contenedorProgramas.setValueAt(est.getNombre(), i, 6);
                contenedorProgramas.setValueAt(p.getRutProfesional(), i, 7);
                contenedorProgramas.setValueAt(prof.getNombres()+" "+prof.getApellidoPaterno()+" "+prof.getApellidoMaterno(), i, 8);
                contenedorProgramas.setValueAt(p.getDiagnosticoProfesional(), i, 9);
                i++;
            }
        }
    }
    public void normalizarEtiquetaMensajeria(){
        etiquetaMensajeria.setText("Área de mensajería");
        etiquetaMensajeria.setForeground(Color.black);
    }
   public void cambiarEtiquetaMensajeria(String mensaje, Color color){
        etiquetaMensajeria.setText(mensaje);
        etiquetaMensajeria.setForeground(color);
    }
   
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton botonAgregarPrograma;
    private javax.swing.JButton botonModificarPrograma;
    private javax.swing.JButton botonNoEliminar;
    private javax.swing.JButton botonSiEliminar;
    private javax.swing.JButton botonVerPrograma;
    public javax.swing.JTable contenedorProgramas;
    private javax.swing.JTextField datosABuscar;
    private javax.swing.JDialog dialogoEliminarPrograma;
    private javax.swing.JLabel etiquetaEliminar;
    private javax.swing.JLabel etiquetaMensajeria;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JPanel jPanel7;
    private javax.swing.JPanel jPanel8;
    private javax.swing.JScrollPane jScrollPane4;
    // End of variables declaration//GEN-END:variables
    
    /**
     *@method método que borra todas las filas de la tablaPacientes
     */   
    public void limpiarTabla(){
        DefaultTableModel temp = (DefaultTableModel) contenedorProgramas.getModel();
        for(int i = contenedorProgramas.getRowCount() -1; i >= 0; i--){
            temp.removeRow(i);
        } 
    }
    
    
    public void actualizarTabla(){
        this.limpiarTabla();
        java.util.List<service.ProgramaMedicoFonasa> programas = (java.util.List<service.ProgramaMedicoFonasa>) listarProgramasFonasa();
        int i = 0;
        for(service.ProgramaMedicoFonasa p : programas){
            if(p.isVisible()){
                this.agregarFila();
                service.Paciente afiliado = (service.Paciente) cargarPaciente(p.getRutAfiliado());
                service.Paciente paciente = (service.Paciente) cargarPaciente(p.getRutPaciente());                                
                service.Usuario profesional = (service.Usuario) cargarUsuario(p.getRutProfesional());                
                service.Establecimiento establecimiento = (service.Establecimiento) cargarEstablecimiento(p.getRutEstablecimiento());
                contenedorProgramas.setValueAt(p.getNumeroPrograma()+"", i, 0);                
                if(afiliado!=null){
                    contenedorProgramas.setValueAt(p.getRutAfiliado()+"", i, 1);
                    contenedorProgramas.setValueAt(afiliado.getNombres()+" "+afiliado.getApellidoPaterno()+" "+afiliado.getApellidoMaterno(), i, 2);
                }
                 
                if(paciente!=null){
                    contenedorProgramas.setValueAt(p.getRutPaciente()+"", i, 3);  
                    contenedorProgramas.setValueAt(paciente.getNombres()+" "+paciente.getApellidoPaterno()+" "+paciente.getApellidoMaterno(), i, 4);
                }
                    
                if(establecimiento!=null){
                    contenedorProgramas.setValueAt(p.getRutEstablecimiento()+"", i, 5);               
                    contenedorProgramas.setValueAt(establecimiento.getNombre(), i, 6);
                }
                else{
                    contenedorProgramas.setValueAt(profesional.getRut()+"", i, 5);               
                    contenedorProgramas.setValueAt(profesional.getNombres()+" "+profesional.getApellidoPaterno()+" "+profesional.getApellidoMaterno(), i, 6);
                }               
                if(profesional!=null){
                    contenedorProgramas.setValueAt(p.getRutProfesional()+"", i, 7);
                    contenedorProgramas.setValueAt(profesional.getNombres()+" "+profesional.getApellidoPaterno()+" "+profesional.getApellidoMaterno(), i, 8);                              
                }
                else{
                    contenedorProgramas.setValueAt(establecimiento.getRut()+"", i, 7);
                    contenedorProgramas.setValueAt(establecimiento.getNombre(), i, 8);                              
                }
                contenedorProgramas.setValueAt(p.getDiagnosticoProfesional()+"", i, 9);
                i++;
            }
        }
    }
        
    public void agregarFila(){
        DefaultTableModel temp = (DefaultTableModel) contenedorProgramas.getModel();
        Object nuevo[]= {"","","","","","","","","","",false};
        temp.addRow(nuevo);
    }

    private static Object cargarPaciente(java.lang.String rut) {
        service.PacienteWS_Service service = new service.PacienteWS_Service();
        service.PacienteWS port = service.getPacienteWSPort();
        return port.cargarPaciente(rut);
    }    

    private static Object cargarUsuario(java.lang.String rut) {
        service.UsuarioWSService service = new service.UsuarioWSService();
        service.UsuarioWS port = service.getUsuarioWSPort();
        return port.cargarUsuario(rut);
    }        

    private static Long registrar(service.Usuario usuario, java.lang.String modulo, java.lang.String accion, java.lang.String valorAnterior, java.lang.String valorNuevo) {
        service.BitacoraWSService service = new service.BitacoraWSService();
        service.BitacoraWS port = service.getBitacoraWSPort();
        return port.registrar(usuario, modulo, accion, valorAnterior, valorNuevo);
    }       

    private static Object cargarPrivilegios(java.lang.String rut) {
        service.PrivilegiosWS_Service service = new service.PrivilegiosWS_Service();
        service.PrivilegiosWS port = service.getPrivilegiosWSPort();
        return port.cargarPrivilegios(rut);
    }    

    private static Object cargarEstablecimiento(java.lang.String rut) {
        service.ProgramaFonasaWSService service = new service.ProgramaFonasaWSService();
        service.ProgramaFonasaWS port = service.getProgramaFonasaWSPort();
        return port.cargarEstablecimiento(rut);
    }   

    private static java.util.List<service.ProgramaMedicoFonasa> filtrarProgramaFonasa(java.lang.String buscar) {
        service.ProgramaFonasaWSService service = new service.ProgramaFonasaWSService();
        service.ProgramaFonasaWS port = service.getProgramaFonasaWSPort();
        return port.filtrarProgramaFonasa(buscar);
    }

    private static java.util.List<service.ProgramaMedicoFonasa> listarProgramasFonasa() {
        service.ProgramaFonasaWSService service = new service.ProgramaFonasaWSService();
        service.ProgramaFonasaWS port = service.getProgramaFonasaWSPort();
        return port.listarProgramasFonasa();
    }

    private static Object cargarProgramaFonasa(java.lang.Long id) {
        service.ProgramaFonasaWSService service = new service.ProgramaFonasaWSService();
        service.ProgramaFonasaWS port = service.getProgramaFonasaWSPort();
        return port.cargarProgramaFonasa(id);
    }

    private static Object cargarProgramaFonasaPorNumero(java.lang.String id) {
        service.ProgramaFonasaWSService service = new service.ProgramaFonasaWSService();
        service.ProgramaFonasaWS port = service.getProgramaFonasaWSPort();
        return port.cargarProgramaFonasaPorNumero(id);
    }

    
}